/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.PA165.musiclibrarybackend.services;

import cz.muni.fi.PA165.musiclibraryapi.dto.AlbumDTOInterface;
import cz.muni.fi.PA165.musiclibraryapi.services.AlbumService;
import cz.muni.fi.PA165.musiclibrarybackend.dao.AlbumDAO;
import cz.muni.fi.PA165.musiclibrarybackend.entities.Album;
import cz.muni.fi.PA165.musiclibrarybackend.transfers.AlbumT;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Dominik
 */
@Service
@Transactional
public class AlbumServiceImpl implements AlbumService, Serializable{

    private AlbumDAO albumDAO;
    
    public void setAlbumDAO(AlbumDAO albumDAO) {
        this.albumDAO = albumDAO;
    }

    public void createAlbum(AlbumDTOInterface album) {
        albumDAO.createAlbum(AlbumT.DTOtoAlbum(album));
    }

    public AlbumDTOInterface getAlbum(Long id) {
        return AlbumT.AlbumToDTO(albumDAO.getAlbum(id));
    }

    public List<AlbumDTOInterface> getAllAlbums() {
        List<AlbumDTOInterface> allAlbumsDTO = new ArrayList();
        List<Album> allAlbums = albumDAO.getAllAlbums();
        for(Album album : allAlbums) {
            allAlbumsDTO.add(AlbumT.AlbumToDTO(album));
        }
        return allAlbumsDTO;
    }

    public void updateAlbum(AlbumDTOInterface album) {
        albumDAO.updateAlbum(AlbumT.DTOtoAlbum(album));
    }

    public void deleteAlbum(AlbumDTOInterface album) {
        albumDAO.deleteAlbum(AlbumT.DTOtoAlbum(album));
    }

}
